import redis
# 连接redis的方法
def redis_link():
    redis_local = redis.StrictRedis(host="39.107.245.102",port="6379",password="wuji5201314.")
    redis_local.set("username","gongqinglu")
    print(redis_local.get("username"))
    # 取值取出来的为（b'gongqinglu'）表示字节串
    # 要想使用字符串，直接解码即可
    print(redis_local.get("username").decode())
    # 输出结果为（gongqinglu）
    # 中文也需要进行解码，否则就是字节串的模式
    redis_local.set("name2", "宫庆禄")
    print(redis_local.get("name2"))
    print(redis_local.get("name2").decode())
    print(type(redis_local.get("name2").decode()))


if __name__=="__main__":
    redis_link()

